package c.e.a.b.f.b;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.DeadObjectException;
import b.i.b.f;
import c.e.a.b.b.h.b.a;
import c.e.a.b.b.h.b.b;
import com.google.android.gms.common.ConnectionResult;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final class k8 implements ServiceConnection, a, b {
    public volatile boolean a;
    public volatile r3 b;
    public final /* synthetic */ q7 c;

    public k8(q7 q7Var) {
        this.c = q7Var;
    }

    public final void a(ConnectionResult connectionResult) {
        f.M("MeasurementServiceConnection.onConnectionFailed");
        u4 u4Var = this.c.a;
        q3 q3Var = u4Var.i;
        q3 q3Var2 = (q3Var == null || !q3Var.n()) ? null : u4Var.i;
        if (q3Var2 != null) {
            q3Var2.i.b("Service connection failed", connectionResult);
        }
        synchronized (this) {
            this.a = false;
            this.b = null;
        }
        this.c.a().v(new n8(this));
    }

    public final void b(Bundle bundle) {
        f.M("MeasurementServiceConnection.onConnected");
        synchronized (this) {
            try {
                this.c.a().v(new l8(this, (i3) this.b.b()));
            } catch (DeadObjectException | IllegalStateException unused) {
                this.b = null;
                this.a = false;
            }
        }
    }

    public final void onConnectionSuspended(int i) {
        f.M("MeasurementServiceConnection.onConnectionSuspended");
        this.c.d().m.a("Service connection suspended");
        this.c.a().v(new o8(this));
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:19:0x0059 */
    /* JADX WARNING: Can't wrap try/catch for region: R(2:19|20) */
    /* JADX WARNING: Missing block: B:20:?, code skipped:
            r3.c.d().f.a("Service connect failed to get IMeasurementService");
     */
    public final void onServiceConnected(android.content.ComponentName r4, android.os.IBinder r5) {
        /*
        r3 = this;
        r4 = "MeasurementServiceConnection.onServiceConnected";
        b.i.b.f.M(r4);
        monitor-enter(r3);
        r4 = 0;
        if (r5 != 0) goto L_0x001d;
    L_0x0009:
        r3.a = r4;	 Catch:{ all -> 0x001a }
        r4 = r3.c;	 Catch:{ all -> 0x001a }
        r4 = r4.d();	 Catch:{ all -> 0x001a }
        r4 = r4.f;	 Catch:{ all -> 0x001a }
        r5 = "Service connected with null binder";
        r4.a(r5);	 Catch:{ all -> 0x001a }
        monitor-exit(r3);	 Catch:{ all -> 0x001a }
        return;
    L_0x001a:
        r4 = move-exception;
        goto L_0x008d;
    L_0x001d:
        r0 = 0;
        r1 = r5.getInterfaceDescriptor();	 Catch:{ RemoteException -> 0x0059 }
        r2 = "com.google.android.gms.measurement.internal.IMeasurementService";
        r2 = r2.equals(r1);	 Catch:{ RemoteException -> 0x0059 }
        if (r2 == 0) goto L_0x004b;
    L_0x002a:
        r1 = "com.google.android.gms.measurement.internal.IMeasurementService";
        r1 = r5.queryLocalInterface(r1);	 Catch:{ RemoteException -> 0x0059 }
        r2 = r1 instanceof c.e.a.b.f.b.i3;	 Catch:{ RemoteException -> 0x0059 }
        if (r2 == 0) goto L_0x0037;
    L_0x0034:
        r1 = (c.e.a.b.f.b.i3) r1;	 Catch:{ RemoteException -> 0x0059 }
        goto L_0x003c;
    L_0x0037:
        r1 = new c.e.a.b.f.b.k3;	 Catch:{ RemoteException -> 0x0059 }
        r1.m5856init(r5);	 Catch:{ RemoteException -> 0x0059 }
    L_0x003c:
        r0 = r1;
        r5 = r3.c;	 Catch:{ RemoteException -> 0x0059 }
        r5 = r5.d();	 Catch:{ RemoteException -> 0x0059 }
        r5 = r5.n;	 Catch:{ RemoteException -> 0x0059 }
        r1 = "Bound to IMeasurementService interface";
        r5.a(r1);	 Catch:{ RemoteException -> 0x0059 }
        goto L_0x0066;
    L_0x004b:
        r5 = r3.c;	 Catch:{ RemoteException -> 0x0059 }
        r5 = r5.d();	 Catch:{ RemoteException -> 0x0059 }
        r5 = r5.f;	 Catch:{ RemoteException -> 0x0059 }
        r2 = "Got binder with a wrong descriptor";
        r5.b(r2, r1);	 Catch:{ RemoteException -> 0x0059 }
        goto L_0x0066;
    L_0x0059:
        r5 = r3.c;	 Catch:{ all -> 0x001a }
        r5 = r5.d();	 Catch:{ all -> 0x001a }
        r5 = r5.f;	 Catch:{ all -> 0x001a }
        r1 = "Service connect failed to get IMeasurementService";
        r5.a(r1);	 Catch:{ all -> 0x001a }
    L_0x0066:
        if (r0 != 0) goto L_0x007d;
    L_0x0068:
        r3.a = r4;	 Catch:{ all -> 0x001a }
        r4 = c.e.a.b.b.i.a.a();	 Catch:{ IllegalArgumentException -> 0x008b }
        r5 = r3.c;	 Catch:{ IllegalArgumentException -> 0x008b }
        r0 = r5.a;	 Catch:{ IllegalArgumentException -> 0x008b }
        r0 = r0.a;	 Catch:{ IllegalArgumentException -> 0x008b }
        r5 = r5.c;	 Catch:{ IllegalArgumentException -> 0x008b }
        java.util.Objects.requireNonNull(r4);	 Catch:{ IllegalArgumentException -> 0x008b }
        r0.unbindService(r5);	 Catch:{ IllegalArgumentException -> 0x008b }
        goto L_0x008b;
    L_0x007d:
        r4 = r3.c;	 Catch:{ all -> 0x001a }
        r4 = r4.a();	 Catch:{ all -> 0x001a }
        r5 = new c.e.a.b.f.b.j8;	 Catch:{ all -> 0x001a }
        r5.m1439init(r3, r0);	 Catch:{ all -> 0x001a }
        r4.v(r5);	 Catch:{ all -> 0x001a }
    L_0x008b:
        monitor-exit(r3);	 Catch:{ all -> 0x001a }
        return;
    L_0x008d:
        monitor-exit(r3);	 Catch:{ all -> 0x001a }
        throw r4;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.b.f.b.k8.onServiceConnected(android.content.ComponentName, android.os.IBinder):void");
    }

    public final void onServiceDisconnected(ComponentName componentName) {
        f.M("MeasurementServiceConnection.onServiceDisconnected");
        this.c.d().m.a("Service disconnected");
        this.c.a().v(new m8(this, componentName));
    }
}
